<?php
class OfficeAction extends BaseAction {
	public function index() {
		$quyu = M ( "area" )->select ();
		$this->assign ( "area", $quyu );
		$type = M ( "type" )->select ();
		$this->assign ( "type", $type );
		$rent = M ( "rent" )->select ();
		$this->assign ( "rent", $rent );
		if (! $this->isPost ()) {
			import ( "ORG.Util.Page" );
			$count = M ( "xiezilou" )->count ();
			$page = new Page ( $count, 15 );
			$show = $page->show ();
			$result = M ( "xiezilou" )->limit ( $page->firstRow . ',' . $page->listRows )->select ();
			$this->assign ( "xiezilou", $result );
			$start = $page->firstRow + 1;
			$end = $start + 14;
			if ($end > $count) {
				$end = $count;
			}
			$this->assign ( "count", $count );
			$this->assign ( "start", $start );
			$this->assign ( "end", $end );
			$this->assign ( "page", $show );
			$this->display ();
		} else {
			$sql = '';
			if ($_POST ['areas'] != '') {
				if ($sql == '') {
					$sql .= "x_quyu='$_POST[areas]'";
				} else {
					$sql .= " and x_quyu='$_POST[areas]'";
				}
			}
			if ($_POST ['zongjias'] != '') {
				$zongjia = $_POST ['zongjias'];
				$money = explode ( "-", $zongjia );
				if ($sql == '') {
					$sql .= "x_zongjia>=$money[0] and x_zongjia<=$money[1]";
				} else {
					$sql .= " and x_zongjia>=$money[0] and x_zongjia<=$money[1]";
				}
			}
			if ($_POST ['subways'] != '') {
				if ($sql == '') {
					$sql .= "x_subway='$_POST[subways]'";
				} else {
					$sql .= " and x_subway='$_POST[subways]'";
				}
			}
			if ($_POST ['types'] != '') {
				if ($sql == '') {
					$sql .= "x_type='$_POST[types]'";
				} else {
					$sql .= " and x_type='$_POST[types]'";
				}
			}
			if ($_POST ['rents'] != '') {
				if ($sql == '') {
					$sql .= "x_rent='$_POST[rents]'";
				} else {
					$sql .= " and x_rent='$_POST[rents]'";
				}
			}
			
			$this->assign ( "areas", $_POST ['areas'] );
			$this->assign ( "zongjias", $_POST ['zongjias'] );
			$this->assign ( "subways", $_POST ['subways'] );
			$this->assign ( "types", $_POST ['types'] );
			$this->assign ( "rents", $_POST ['rents'] );
			import ( "ORG.Util.Page" );
			$count = M ( "xiezilou" )->where ( $sql )->count ();
			$page = new Page ( $count, 15 );
			$show = $page->show ();
			$result = M ( "xiezilou" )->where ( $sql )->limit ( $page->firstRow . ',' . $page->listRows )->select ();
			$this->assign ( "xiezilou", $result );
			$start = $page->firstRow + 1;
			$end = $start + 14;
			if ($end > $count) {
				$end = $count;
			}
			$this->assign ( "count", $count );
			$this->assign ( "start", $start );
			$this->assign ( "end", $end );
			$this->assign ( "page", $show );
			$this->display ( "lists" );
		}
	}
}

?>